#include "serial_device.h"

int serial_device_open(char *path) {
	int rt = open(path, O_RDWR | O_NOCTTY | O_NDELAY);
	if(rt == ERROR)
		perror("Error function open_serial_device");
	else fcntl(rt, F_SETFL, 0);
	return rt;
}

int serial_device_read(int descriptor, void *data) {
	int rt = read(descriptor, data, sizeof(data));
	if(rt == ERROR)
		perror("Error function read_serial_device");
	return rt;
}

int serial_device_write(int descriptor, void *data) {
	int rt = write(descriptor, data, sizeof(data));
	if(rt == ERROR)
		perror("Error function write_serial_device");
	return rt;
}

int serial_device_close(int descriptor) {
	int rt = close(descriptor);
	if(rt == ERROR)
		perror("Error function close_serial_device");
	return rt;
}
